package com.itggm.controller;

import com.itggm.DTO.CoursePageDTO;
import com.itggm.pojo.Course;
import com.itggm.response.ResponseResult;
import com.itggm.service.CourseService;
import com.itggm.utils.AliOSSUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author: ggm
 * @data 2024年11月21日 20:02
 */
@RestController
@RequestMapping("/course")
public class CourseController {
    @Autowired
    private CourseService courseService;
    @Autowired
    private AliOSSUtil aliOSSUtil;

    /**
     * @Author: ggm
     * @date: 2024/11/21
     * 分页查询
     */
    @GetMapping("/page")
    public ResponseResult page(CoursePageDTO coursePageDTO) {
        return courseService.page(coursePageDTO);

    }

    /**
     * @Author: ggm
     * @date: 2024/11/22
     * 上传文件
     */
    @PostMapping("upload")
    public ResponseResult upload(MultipartFile file) throws IOException {
        String url = aliOSSUtil.upload(file);
        return ResponseResult.success().data(url);
    }

    /**
     * @Author: ggm
     * @date: 2024/11/22
     * 更新图片文件
     */
    @PostMapping("/updateImg")
    public ResponseResult updateImg(String courseId, String fileName, String img) {
        return courseService.editCourseImg(courseId, fileName, img);
    }
     /**
      * @Author: ggm
      * @date:  2024/11/22
      * 删除文件
      */

    @PostMapping("delete")
    public ResponseResult deleteCourse(String img) {
        return courseService.deleteCourse(img);
    }
     /**
      * @Author: ggm
      * @date:  2024/11/22
      * 添加课程
      */
     @PostMapping("/uploadInfo")
     public ResponseResult  addUploadInfo(Course course){

       return courseService.addCoure(course);
    }
     /**
      * @Author: ggm
      * @date:  2024/11/22
      * 修改课程信息
      */
     @PostMapping("update")
    public ResponseResult  updateCourse(Course course){

        return courseService.updateCoure(course);
    }
     /**
      * @Author: ggm
      * @date:  2024/11/25
      * 前端界面获取课程信息
      */
     @GetMapping("/front/list")
     public ResponseResult getCourseInfo(Integer limit){
         return courseService.getCoachInfo(limit);

     }
      /**
       * @Author: ggm
       * @date:  2024/11/26
       * 获取课程列表
       */
      @GetMapping("/list")
      public  ResponseResult getCourseList(){
          return courseService.getCourseList();
      }
}
